using System;
using System.Data;
using System.Xml;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using Widgetsphere.Core.Logging;
using Widgetsphere.Core.Exceptions;
using Widgetsphere.Core.DataAccess;
using Acme.Sales.Business;
using Acme.Sales.Business.Rules;
using Widgetsphere.Core.WinUI;
using Acme.Sales.Domain.Objects;
using System.ComponentModel;
using Widgetsphere.Core.EventArgs;
using Acme.Sales.Business.Objects.Composites;
using System.IO;

namespace Acme.Sales.Business.Objects
{
	/// <summary>
	/// Interface definition for the 'Customer' entity
	/// </summary>
	public interface ICustomer : IPersistableBusinessObject, IAuditable, ICloneable
	{
		#region Properties

		/// <summary>
		/// The Address field
		/// </summary>
		string Address { get; set; }
		/// <summary>
		/// The City field
		/// </summary>
		string City { get; set; }
		/// <summary>
		/// The Country field
		/// </summary>
		string Country { get; set; }
		/// <summary>
		/// The Fax field
		/// </summary>
		string Fax { get; set; }
		/// <summary>
		/// The FirstName field
		/// </summary>
		string FirstName { get; set; }
		/// <summary>
		/// The LastName field
		/// </summary>
		string LastName { get; set; }
		/// <summary>
		/// The MiddleName field
		/// </summary>
		string MiddleName { get; set; }
		/// <summary>
		/// The Phone field
		/// </summary>
		string Phone { get; set; }
		/// <summary>
		/// The PostalCode field
		/// </summary>
		string PostalCode { get; set; }
		/// <summary>
		/// The Region field
		/// </summary>
		string Region { get; set; }
		/// <summary>
		/// The UserId field
		/// </summary>
		int UserId { get; }

		#endregion

		#region Methods

		/// <summary>
		/// This event is called before persisting to the database.
		/// </summary>
		event EventHandler<BusinessObjectEventArgs> Validate;

		/// <summary>
		/// Removes this object from its parent collection. It will not be deleted from the database.
		/// </summary>
		void Remove();

		/// <summary>
		/// The primary key for this object
		/// </summary>
		new CustomerPrimaryKey PrimaryKey { get; }

		/// <summary>
		/// Persists this object to the database.
		/// </summary>
		new void Persist();

		/// <summary>
		/// Creates a clone of this object.
		/// </summary>
		new IBusinessObject Clone();

		#endregion

	}

	/// <summary>
	/// Class definition for the 'Customer' entity
	/// </summary>
	[Serializable()]
	public partial class Customer : BusinessObjectPersistableBase, IPersistableBusinessObject, ICustomer
	{
		#region Class Members

		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'Customer' table.
		/// </summary>
		public enum FieldNameConstants
		{
			 /// <summary>
			 /// Field mapping for the 'UserId' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'UserId' property")]
			UserId,
			 /// <summary>
			 /// Field mapping for the 'Region' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Region' property")]
			Region,
			 /// <summary>
			 /// Field mapping for the 'PostalCode' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'PostalCode' property")]
			PostalCode,
			 /// <summary>
			 /// Field mapping for the 'Phone' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Phone' property")]
			Phone,
			 /// <summary>
			 /// Field mapping for the 'MiddleName' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'MiddleName' property")]
			MiddleName,
			 /// <summary>
			 /// Field mapping for the 'LastName' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'LastName' property")]
			LastName,
			 /// <summary>
			 /// Field mapping for the 'FirstName' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'FirstName' property")]
			FirstName,
			 /// <summary>
			 /// Field mapping for the 'Fax' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Fax' property")]
			Fax,
			 /// <summary>
			 /// Field mapping for the 'Country' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Country' property")]
			Country,
			 /// <summary>
			 /// Field mapping for the 'City' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'City' property")]
			City,
			 /// <summary>
			 /// Field mapping for the 'Address' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Address' property")]
			Address,
			 /// <summary>
			 /// Field mapping for the 'CreatedBy' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedBy' property")]
			CreatedBy,
			 /// <summary>
			 /// Field mapping for the 'CreatedDate' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedDate' property")]
			CreatedDate,
			 /// <summary>
			 /// Field mapping for the 'ModifiedBy' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedBy' property")]
			ModifiedBy,
			 /// <summary>
			 /// Field mapping for the 'ModifiedDate' property
			 /// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedDate' property")]
			ModifiedDate,
		}
		#endregion

		internal DomainCustomer wrappedClass;

		#endregion

		#region Constructors

		/// <summary>
		/// Creates a 'Customer' object from a domain object
		/// </summary>
		internal Customer(DomainCustomer classToWrap)
		{
			wrappedClass = classToWrap;
		}

		/// <summary>
		/// Creates a 'Customer' object from a DataRowView
		/// </summary>
		internal Customer(DataRowView drvToWrap)
		{
			wrappedClass = (DomainCustomer)drvToWrap.Row;
		}

		#endregion

		#region Events

		/// <summary>
		/// This event is raised before the 'Address' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> AddressChanging;

		/// <summary>
		/// This event is raised when the 'Address' field is changed.
		/// </summary>
		public event EventHandler AddressChanged;

		/// <summary>
		/// This event is raised before the 'City' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> CityChanging;

		/// <summary>
		/// This event is raised when the 'City' field is changed.
		/// </summary>
		public event EventHandler CityChanged;

		/// <summary>
		/// This event is raised before the 'Country' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> CountryChanging;

		/// <summary>
		/// This event is raised when the 'Country' field is changed.
		/// </summary>
		public event EventHandler CountryChanged;

		/// <summary>
		/// This event is raised before the 'Fax' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> FaxChanging;

		/// <summary>
		/// This event is raised when the 'Fax' field is changed.
		/// </summary>
		public event EventHandler FaxChanged;

		/// <summary>
		/// This event is raised before the 'FirstName' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> FirstNameChanging;

		/// <summary>
		/// This event is raised when the 'FirstName' field is changed.
		/// </summary>
		public event EventHandler FirstNameChanged;

		/// <summary>
		/// This event is raised before the 'LastName' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> LastNameChanging;

		/// <summary>
		/// This event is raised when the 'LastName' field is changed.
		/// </summary>
		public event EventHandler LastNameChanged;

		/// <summary>
		/// This event is raised before the 'MiddleName' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> MiddleNameChanging;

		/// <summary>
		/// This event is raised when the 'MiddleName' field is changed.
		/// </summary>
		public event EventHandler MiddleNameChanged;

		/// <summary>
		/// This event is raised before the 'Phone' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> PhoneChanging;

		/// <summary>
		/// This event is raised when the 'Phone' field is changed.
		/// </summary>
		public event EventHandler PhoneChanged;

		/// <summary>
		/// This event is raised before the 'PostalCode' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> PostalCodeChanging;

		/// <summary>
		/// This event is raised when the 'PostalCode' field is changed.
		/// </summary>
		public event EventHandler PostalCodeChanged;

		/// <summary>
		/// This event is raised before the 'Region' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<string>> RegionChanging;

		/// <summary>
		/// This event is raised when the 'Region' field is changed.
		/// </summary>
		public event EventHandler RegionChanged;

		/// <summary>
		/// This event is raised before the 'UserId' field is changed providing a chance to cancel the action.
		/// </summary>
		public event EventHandler<BusinessObjectCancelEventArgs<int>> UserIdChanging;

		/// <summary>
		/// This event is raised when the 'UserId' field is changed.
		/// </summary>
		public event EventHandler UserIdChanged;

		/// <summary>
		/// Raises the AddressChanging event.
		/// </summary>
		protected virtual void OnAddressChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.AddressChanging != null)
				this.AddressChanging(this, e);
		}

		/// <summary>
		/// Raises the AddressChanged event.
		/// </summary>
		protected virtual void OnAddressChanged(System.EventArgs e)
		{
			if (this.AddressChanged != null)
				this.AddressChanged(this, e);
		}

		/// <summary>
		/// Raises the CityChanging event.
		/// </summary>
		protected virtual void OnCityChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.CityChanging != null)
				this.CityChanging(this, e);
		}

		/// <summary>
		/// Raises the CityChanged event.
		/// </summary>
		protected virtual void OnCityChanged(System.EventArgs e)
		{
			if (this.CityChanged != null)
				this.CityChanged(this, e);
		}

		/// <summary>
		/// Raises the CountryChanging event.
		/// </summary>
		protected virtual void OnCountryChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.CountryChanging != null)
				this.CountryChanging(this, e);
		}

		/// <summary>
		/// Raises the CountryChanged event.
		/// </summary>
		protected virtual void OnCountryChanged(System.EventArgs e)
		{
			if (this.CountryChanged != null)
				this.CountryChanged(this, e);
		}

		/// <summary>
		/// Raises the FaxChanging event.
		/// </summary>
		protected virtual void OnFaxChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.FaxChanging != null)
				this.FaxChanging(this, e);
		}

		/// <summary>
		/// Raises the FaxChanged event.
		/// </summary>
		protected virtual void OnFaxChanged(System.EventArgs e)
		{
			if (this.FaxChanged != null)
				this.FaxChanged(this, e);
		}

		/// <summary>
		/// Raises the FirstNameChanging event.
		/// </summary>
		protected virtual void OnFirstNameChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.FirstNameChanging != null)
				this.FirstNameChanging(this, e);
		}

		/// <summary>
		/// Raises the FirstNameChanged event.
		/// </summary>
		protected virtual void OnFirstNameChanged(System.EventArgs e)
		{
			if (this.FirstNameChanged != null)
				this.FirstNameChanged(this, e);
		}

		/// <summary>
		/// Raises the LastNameChanging event.
		/// </summary>
		protected virtual void OnLastNameChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.LastNameChanging != null)
				this.LastNameChanging(this, e);
		}

		/// <summary>
		/// Raises the LastNameChanged event.
		/// </summary>
		protected virtual void OnLastNameChanged(System.EventArgs e)
		{
			if (this.LastNameChanged != null)
				this.LastNameChanged(this, e);
		}

		/// <summary>
		/// Raises the MiddleNameChanging event.
		/// </summary>
		protected virtual void OnMiddleNameChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.MiddleNameChanging != null)
				this.MiddleNameChanging(this, e);
		}

		/// <summary>
		/// Raises the MiddleNameChanged event.
		/// </summary>
		protected virtual void OnMiddleNameChanged(System.EventArgs e)
		{
			if (this.MiddleNameChanged != null)
				this.MiddleNameChanged(this, e);
		}

		/// <summary>
		/// Raises the PhoneChanging event.
		/// </summary>
		protected virtual void OnPhoneChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.PhoneChanging != null)
				this.PhoneChanging(this, e);
		}

		/// <summary>
		/// Raises the PhoneChanged event.
		/// </summary>
		protected virtual void OnPhoneChanged(System.EventArgs e)
		{
			if (this.PhoneChanged != null)
				this.PhoneChanged(this, e);
		}

		/// <summary>
		/// Raises the PostalCodeChanging event.
		/// </summary>
		protected virtual void OnPostalCodeChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.PostalCodeChanging != null)
				this.PostalCodeChanging(this, e);
		}

		/// <summary>
		/// Raises the PostalCodeChanged event.
		/// </summary>
		protected virtual void OnPostalCodeChanged(System.EventArgs e)
		{
			if (this.PostalCodeChanged != null)
				this.PostalCodeChanged(this, e);
		}

		/// <summary>
		/// Raises the RegionChanging event.
		/// </summary>
		protected virtual void OnRegionChanging(BusinessObjectCancelEventArgs<string> e)
		{
			if (this.RegionChanging != null)
				this.RegionChanging(this, e);
		}

		/// <summary>
		/// Raises the RegionChanged event.
		/// </summary>
		protected virtual void OnRegionChanged(System.EventArgs e)
		{
			if (this.RegionChanged != null)
				this.RegionChanged(this, e);
		}

		/// <summary>
		/// Raises the UserIdChanging event.
		/// </summary>
		protected virtual void OnUserIdChanging(BusinessObjectCancelEventArgs<int> e)
		{
			if (this.UserIdChanging != null)
				this.UserIdChanging(this, e);
		}

		/// <summary>
		/// Raises the UserIdChanged event.
		/// </summary>
		protected virtual void OnUserIdChanged(System.EventArgs e)
		{
			if (this.UserIdChanged != null)
				this.UserIdChanged(this, e);
		}

		#endregion

		#region Properties

		/// <summary>
		/// The current state of this object.
		/// </summary>
		public Widgetsphere.Core.DataAccess.SubDomainBase.ItemStateConstants ItemState
		{
			get { return (Widgetsphere.Core.DataAccess.SubDomainBase.ItemStateConstants)int.Parse(wrappedClass.RowState.ToString("d")); }
		}

		/// <summary>
		/// Determines the type of collection that contains this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public Collections Container
		{
			get { return Collections.CustomerCollection; }
		}

		#region CreatedBy / ModifiedBy Section

		/// <summary>
		/// The audit field for the 'Modified By' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual string ModifiedBy
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.ModifiedByColumn];
				if (o == DBNull.Value) return null;
				else return (string)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.ModifiedByColumn] = value; }
		}

		/// <summary>
		/// The audit field for the 'Modified Date' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual DateTime? ModifiedDate
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn];
				if (o == DBNull.Value) return null;
				else return (DateTime)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn] = value; }
		}

		/// <summary>
		/// Sets 'ModifiedBy' column.
		/// </summary>
		public virtual void SetModifiedDate(DateTime newValue)
		{
			this.wrappedClass[this.wrappedClass.ParentCol.ModifiedDateColumn] = newValue;
		}

		/// <summary>
		/// The audit field for the 'Created By' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual string CreatedBy
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.CreatedByColumn];
				if (o == DBNull.Value) return null;
				else return (string)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.CreatedByColumn] = value; }
		}

		/// <summary>
		/// The audit field for the 'Created Date' column.
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		public virtual DateTime? CreatedDate
		{
			get
			{
				object o = this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn];
				if (o == DBNull.Value) return null;
				else return (DateTime)o;
			}
			internal set { this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn] = value; }
		}

		/// <summary>
		/// Sets 'ModifiedBy' column.
		/// </summary>
		public virtual void SetCreatedDate(DateTime newValue)
		{
			this.wrappedClass[this.wrappedClass.ParentCol.CreatedDateColumn] = newValue;
		}

		[System.ComponentModel.Browsable(false)]
		internal virtual byte[] TimeStamp
		{
			get
			{
				 object o = this.wrappedClass[this.wrappedClass.ParentCol.TimeStampColumn];
				 return (byte[])o;
			}
			set { this.wrappedClass[this.wrappedClass.ParentCol.TimeStampColumn] = value; }
		}

		#endregion

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (((DataRow)this.WrappedClass).RowState != DataRowState.Detached); }
		}

		/// <summary>
		/// Returns the internal object that this object wraps
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		internal virtual object WrappedClass
		{
			get{ return wrappedClass; }
			set{ wrappedClass = (DomainCustomer)value; }
		}

		//WrappingClass Interface
		object IWrappingClass.WrappedClass
		{
			get { return this.WrappedClass; }
			set { this.WrappedClass = value; }
		}

		/// <summary>
		/// The primary key for this object
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual CustomerPrimaryKey PrimaryKey
		{
			get
			{
				try
				{
					return wrappedClass.PrimaryKey;
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: address
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string Address
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.Address)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Address))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.Address", GetMaxLength(FieldNameConstants.Address)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnAddressChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.Address = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("Address"));
						this.OnAddressChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: city
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string City
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.City)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.City))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.City", GetMaxLength(FieldNameConstants.City)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnCityChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.City = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("City"));
						this.OnCityChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: country
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string Country
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.Country)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Country))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.Country", GetMaxLength(FieldNameConstants.Country)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnCountryChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.Country = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("Country"));
						this.OnCountryChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: fax
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string Fax
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.Fax)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Fax))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.Fax", GetMaxLength(FieldNameConstants.Fax)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnFaxChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.Fax = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("Fax"));
						this.OnFaxChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: first_name
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string FirstName
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.FirstName)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.FirstName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.FirstName", GetMaxLength(FieldNameConstants.FirstName)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnFirstNameChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.FirstName = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("FirstName"));
						this.OnFirstNameChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: last_name
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string LastName
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.LastName)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.LastName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.LastName", GetMaxLength(FieldNameConstants.LastName)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnLastNameChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.LastName = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("LastName"));
						this.OnLastNameChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: middle_name
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string MiddleName
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.MiddleName)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.MiddleName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.MiddleName", GetMaxLength(FieldNameConstants.MiddleName)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnMiddleNameChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.MiddleName = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("MiddleName"));
						this.OnMiddleNameChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: phone
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string Phone
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.Phone)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Phone))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.Phone", GetMaxLength(FieldNameConstants.Phone)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnPhoneChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.Phone = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("Phone"));
						this.OnPhoneChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: postal_code
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string PostalCode
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.PostalCode)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.PostalCode))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.PostalCode", GetMaxLength(FieldNameConstants.PostalCode)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnPostalCodeChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.PostalCode = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("PostalCode"));
						this.OnPostalCodeChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: region
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual string Region
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.Region)); }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Region))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Customer.Region", GetMaxLength(FieldNameConstants.Region)));
				try
				{
					BusinessObjectCancelEventArgs<string> cancelArgs = new BusinessObjectCancelEventArgs<string>(value);
					this.OnRegionChanging(cancelArgs);
					if (!cancelArgs.Cancel)
					{
						lock (this)
						{
							wrappedClass.Region = cancelArgs.NewValue;
						}
						this.ModifiedDate = DateTime.Now;
						this.OnPropertyChanged(new PropertyChangedEventArgs("Region"));
						this.OnRegionChanged(new EventArgs());
					}
				}
				catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
				catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
				catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
			}
		}

		/// <summary>
		/// Property for table field: user_id
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[System.ComponentModel.Description("")]
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public virtual int UserId
		{
			get { return GlobalValues.PropertyGetterLambdaErrorHandler(() => (wrappedClass.UserId)); }
		}

		internal virtual void ReleaseNonIdentifyingRelationships()
		{
			try
			{
				wrappedClass.ReleaseNonIdentifyingRelationships();
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}


		#endregion

		#region Collection Operation Methods

		/// <summary>
		/// This event is called before persisting to the database.
		/// </summary>
		public event EventHandler<BusinessObjectEventArgs> Validate;

		/// <summary>
		/// This event is called before persisting to store.
		/// </summary>
		/// <param name="item"></param>
		protected internal void OnValidate(BusinessObjectEventArgs item)
		{
			if (this.Validate != null)
				this.Validate(this, item);
		}

		/// <summary>
		/// Persists this object to the database.
		/// </summary>
		public override void Persist()
		{
		  if (this.IsParented)
		  {
				this.OnValidate(new BusinessObjectEventArgs(this));
			  wrappedClass.Persist();
		  }
		  else
		    throw new Exception("This item is not part of a collection and cannot be persisted!");
		}

		/// <summary>
		/// Removes this object from its parent collection. It will not be deleted from the database.
		/// </summary>
		public void Remove()
		{
			try
			{
				if (this.ParentCollection == null)
				{
					lock (this)
					{
						wrappedClass.Remove();
					}
				}
				else
				{
					lock (this.ParentCollection.SubDomain)
					{
						wrappedClass.Remove();
					}
				}
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		/// <summary>
		/// Marks this object for deletion. The next call to the Persist method will delete it from the database.
		/// </summary>
		public void Delete()
		{
			try
			{
				if (this.ParentCollection == null)
				{
					lock (this)
					{
						wrappedClass.Delete();
					}
				}
				else
				{
					lock (this.ParentCollection.SubDomain)
					{
						wrappedClass.Delete();
					}
				}
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		#endregion

		#region Overrides

		/// <summary>
		/// Serves as a hash function for this particular type.
		/// </summary>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		/// <summary>
		/// Returns a value indicating whether the current object is equal to a specified object.
		/// </summary>
		public override bool Equals(object obj)
		{
			if (obj == null) return false;
			if (obj.GetType() == this.GetType())
			{
				if (this.wrappedClass.Equals(((Customer)obj).wrappedClass))
					return true;
			}
			else if(obj.GetType() == this.PrimaryKey.GetType())
			{
			  if(this.PrimaryKey.Equals(obj))
			    return true;
			}
			else if (obj.GetType() == this.PrimaryKey.UserId.GetType())
			{
				if (this.PrimaryKey.UserId.Equals(obj))
					return true;
			}
			return false;
		}

		#endregion

		#region IBusinessObject ParentCollection

		/// <summary>
		/// This is a reference back to the generic collection that holds this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		IBusinessCollection IBusinessObject.ParentCollection
		{
			get { return this.ParentCollection; }
		}

		#endregion

		#region ParentCollection

		/// <summary>
		/// This is a reference back to the collection that holds this object.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public CustomerCollection ParentCollection
		{
			get { return new CustomerCollection(wrappedClass.ParentCol); }
		}

		#endregion

		#region GetDefault

		/// <summary>
		/// Gets the default value of one of this object's properties.
		/// </summary>
		public object GetDefault(FieldNameConstants field)
		{
			if(field == FieldNameConstants.Address)
				return "";
			if(field == FieldNameConstants.City)
				return "";
			if(field == FieldNameConstants.Country)
				return "";
			if(field == FieldNameConstants.Fax)
				return "";
			if(field == FieldNameConstants.FirstName)
				return "";
			if(field == FieldNameConstants.LastName)
				return "";
			if(field == FieldNameConstants.MiddleName)
				return "";
			if(field == FieldNameConstants.Phone)
				return "";
			if(field == FieldNameConstants.PostalCode)
				return "";
			if(field == FieldNameConstants.Region)
				return "";
			if(field == FieldNameConstants.UserId)
				return 0;

			return null;
		}

		object IBusinessObject.GetDefault(Enum field)
		{
			return this.GetDefault((FieldNameConstants)field);
		}

		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if(field == FieldNameConstants.UserId)
				return this.UserId;
			if(field == FieldNameConstants.Region)
				return ((this.Region == null) ? defaultValue : this.Region);
			if(field == FieldNameConstants.PostalCode)
				return ((this.PostalCode == null) ? defaultValue : this.PostalCode);
			if(field == FieldNameConstants.Phone)
				return ((this.Phone == null) ? defaultValue : this.Phone);
			if(field == FieldNameConstants.MiddleName)
				return ((this.MiddleName == null) ? defaultValue : this.MiddleName);
			if(field == FieldNameConstants.LastName)
				return this.LastName;
			if(field == FieldNameConstants.FirstName)
				return this.FirstName;
			if(field == FieldNameConstants.Fax)
				return ((this.Fax == null) ? defaultValue : this.Fax);
			if(field == FieldNameConstants.Country)
				return ((this.Country == null) ? defaultValue : this.Country);
			if(field == FieldNameConstants.City)
				return ((this.City == null) ? defaultValue : this.City);
			if(field == FieldNameConstants.Address)
				return ((this.Address == null) ? defaultValue : this.Address);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(FieldNameConstants field)
		{
			return this.GetInteger(field, int.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(FieldNameConstants field, int defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				int a;
				if (int.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (int)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(FieldNameConstants field)
		{
			return this.GetDouble(field, double.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(FieldNameConstants field, double defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				double a;
				if (double.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (double)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public DateTime GetDateTime(FieldNameConstants field)
		{
			return this.GetDateTime(field, DateTime.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public DateTime GetDateTime(FieldNameConstants field, DateTime defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				DateTime a;
				if (DateTime.TryParse((string)o, out a))
					return a;
				else
					throw new InvalidCastException();
			}
			else
			{
				return (DateTime)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(FieldNameConstants field)
		{
			return this.GetString(field, "");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(FieldNameConstants field, string defaultValue)
		{
			object o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				return (string)o;
			}
			else
			{
				return o.ToString();
			}
		}

		#endregion

		#region SetValue

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		public void SetValue(FieldNameConstants field, object newValue)
		{
			SetValue(field, newValue, false);
		}

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		/// <param name="fixLength">Determines if the length should be truncated if too long. When false, an error will be raised if data is too large to be assigned to the field.</param>
		public void SetValue(FieldNameConstants field, object newValue, bool fixLength)
		{
			if (field == FieldNameConstants.UserId)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.Region)
			{
				this.Region = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.PostalCode)
			{
				this.PostalCode = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.Phone)
			{
				this.Phone = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.MiddleName)
			{
				this.MiddleName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.LastName)
			{
				this.LastName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.FirstName)
			{
				this.FirstName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.Fax)
			{
				this.Fax = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.Country)
			{
				this.Country = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.City)
			{
				this.City = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
			else if (field == FieldNameConstants.Address)
			{
				this.Address = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetFieldLength(field));
			}
		else
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region GetFieldLength

		/// <summary>
		/// Determines the length of the specified field if it can be set.
		/// </summary>
		public int GetFieldLength(Customer.FieldNameConstants field)
		{
			if(field == FieldNameConstants.Region) return 50;
			if(field == FieldNameConstants.PostalCode) return 50;
			if(field == FieldNameConstants.Phone) return 50;
			if(field == FieldNameConstants.MiddleName) return 50;
			if(field == FieldNameConstants.LastName) return 50;
			if(field == FieldNameConstants.FirstName) return 50;
			if(field == FieldNameConstants.Fax) return 50;
			if(field == FieldNameConstants.Country) return 50;
			if(field == FieldNameConstants.City) return 50;
			if(field == FieldNameConstants.Address) return 50;
			//Catch all for all other data types
			return -1;
		}
		#endregion

		#region Reject Changes

		/// <summary>
		/// Rejects all the changes for this object, since the last load
		/// </summary>
		/// <returns>void</returns>
		public virtual void RejectChanges()
		{
		  DomainCustomer coll = (DomainCustomer)this.wrappedClass;
		  coll.RejectChanges();
		}

		#endregion

		#region Clone

		/// <summary>
		/// Create a copy of this object.
		/// </summary>
		public virtual IBusinessObject Clone()
		{
			lock (this)
			{
				if (!this.IsParented) throw new Exception("The current item must be parented.");
				Customer newItem = null;
				lock (this.ParentCollection.SubDomain)
				{
					newItem = new Customer(this.ParentCollection.wrappedClass.NewItem());
				}
				this.FillClone(newItem);
				return newItem;
			}
		}

		/// <summary>
		/// Create a copy of this object.
		/// <param name="userid">The userid field</param>
		/// </summary>
		public virtual IBusinessObject Clone(int userid)
		{
			lock (this)
			{
				if (!this.IsParented) throw new Exception("The current item must be parented.");
				Customer newItem = null;
				lock (this.ParentCollection.wrappedClass.SubDomain)
				{
				newItem = new Customer(this.ParentCollection.wrappedClass.NewItem(userid));
				}
				this.FillClone(newItem);
				return newItem;
			}
		}

		private void FillClone(Customer newItem)
		{
			lock (this)
			{
				lock (newItem)
				{
					newItem.Region = this.Region;
					newItem.PostalCode = this.PostalCode;
					newItem.Phone = this.Phone;
					newItem.MiddleName = this.MiddleName;
					newItem.LastName = this.LastName;
					newItem.FirstName = this.FirstName;
					newItem.Fax = this.Fax;
					newItem.Country = this.Country;
					newItem.City = this.City;
					newItem.Address = this.Address;
				}
			}
		}

		object ICloneable.Clone()
		{
			return this.Clone();
		}

		#endregion

		#region Helper Methods

		string IBusinessObject.GetFriendlyName(Enum field)
		{
			return "";
		}

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.Address:
					return 50;
				case FieldNameConstants.City:
					return 50;
				case FieldNameConstants.Country:
					return 50;
				case FieldNameConstants.Fax:
					return 50;
				case FieldNameConstants.FirstName:
					return 50;
				case FieldNameConstants.LastName:
					return 50;
				case FieldNameConstants.MiddleName:
					return 50;
				case FieldNameConstants.Phone:
					return 50;
				case FieldNameConstants.PostalCode:
					return 50;
				case FieldNameConstants.Region:
					return 50;
				case FieldNameConstants.UserId:
					return 0;
			}
			return 0;
		}

		int IBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		string IBusinessObject.GetMask(Enum field)
		{
			return "";
		}

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static Customer SelectUsingPK(int userid)
		{
			return SelectUsingPK(userid, "");
		}

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static Customer SelectUsingPK(int userid, string modifier)
		{
			CustomerCollection customer = CustomerCollection.SelectUsingPK(userid, modifier);
			if (customer.Count > 1) throw new Exception("Customer primary key returned more than one value.");
			else if (customer.Count == 0) return null;
			else return customer[0];
		}

		#endregion

		#region IBusinessObject Members

		IPrimaryKey IBusinessObject.PrimaryKey
		{
			get { return this.PrimaryKey; }
		}

		object IBusinessObject.GetValue(Enum field)
		{
			return this.GetValue((FieldNameConstants)field);
		}

		object IBusinessObject.GetValue(Enum field, object defaultValue)
		{
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		double IBusinessObject.GetDouble(Enum field)
		{
			return this.GetDouble((FieldNameConstants)field);
		}

		double IBusinessObject.GetDouble(Enum field, double defaultValue)
		{
			return this.GetDouble((FieldNameConstants)field, defaultValue);
		}

		DateTime IBusinessObject.GetDateTime(Enum field)
		{
			return this.GetDateTime((FieldNameConstants)field);
		}

		DateTime IBusinessObject.GetDateTime(Enum field, DateTime defaultValue)
		{
			return this.GetDateTime((FieldNameConstants)field, defaultValue);
		}

		int IBusinessObject.GetInteger(Enum field)
		{
			return this.GetInteger((FieldNameConstants)field);
		}

		int IBusinessObject.GetInteger(Enum field, int defaultValue)
		{
			return this.GetInteger((FieldNameConstants)field, defaultValue);
		}

		string IBusinessObject.GetString(Enum field)
		{
			return this.GetString((FieldNameConstants)field);
		}

		string IBusinessObject.GetString(Enum field, string defaultValue)
		{
			return this.GetString((FieldNameConstants)field, defaultValue);
		}

		void IPersistableBusinessObject.SetValue(Enum field, object newValue)
		{
			this.SetValue((FieldNameConstants)field, newValue);
		}

		Enum IBusinessObject.Container
		{
			get { return this.Container; }
		}

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(IBusinessObject item)
		{
			if (item == null) return false;
			if (!(item is Customer)) return false;
			Customer o = item as Customer;
			return (
				o.UserId == this.UserId &&
				o.Region == this.Region &&
				o.PostalCode == this.PostalCode &&
				o.Phone == this.Phone &&
				o.MiddleName == this.MiddleName &&
				o.LastName == this.LastName &&
				o.FirstName == this.FirstName &&
				o.Fax == this.Fax &&
				o.Country == this.Country &&
				o.City == this.City &&
				o.Address == this.Address
				);
		}

		#endregion

		#region IAuditable Members

		string IAuditable.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		DateTime? IAuditable.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		bool IAuditable.IsCreateAuditImplemented
		{
			get { return true; }
		}

		bool IAuditable.IsModifyAuditImplemented
		{
			get { return true; }
		}

		bool IAuditable.IsTimestampAuditImplemented
		{
			get { return true; }
		}

		string IAuditable.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		DateTime? IAuditable.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		byte[] IAuditable.TimeStamp
		{
			get { return this.TimeStamp; }
		}

		#endregion

	}

}
